package com.lemo.cmx.guanchazhe;

/**
 * Created by 罗选通 on 2017/9/13.
 */
public class CurrentConditionsDisplay implements OBserver, DisplayElement {

  private WeatherData weatherData;

  private float temperature;//温度
  private float humidity;//湿度
  private float pressure;//气压

  public CurrentConditionsDisplay(WeatherData weatherData) {
    this.weatherData = weatherData;
    this.weatherData.registerObserver(this);
  }

  @Override
  public void display() {
    System.out.println("当前温度为：" + this.temperature + "℃");
    System.out.println("当前湿度为：" + this.humidity);
    System.out.println("当前气压为：" + this.pressure);
  }

  @Override
  public void update() {
    this.temperature = this.weatherData.getTemperature();
    this.humidity = this.weatherData.getHumidity();
    this.pressure = this.weatherData.getPressure();
    display();
  }
}
